package com.itheima.web.controller.cms;


import com.itheima.result.AjaxResult;
import com.itheima.result.PageResult;
import com.itheima.service.cms.CmsSubjectService;
import com.itheima.vo.cms.CmsSubject;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 前端控制器
 */
@RestController
@RequestMapping("/subject")
public class CmsSubjectController {
    @DubboReference
    private CmsSubjectService cmsSubjectService;

    /**
     * 获取全部商品专题
     * @return
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(){
        List<CmsSubject> list = cmsSubjectService.list();
        return AjaxResult.success("操作成功!",list);
    }

    /**
     * 根据专题名称分页获取商品专题
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/list")
    public AjaxResult listByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 String keyword){
        PageResult pageResult = cmsSubjectService.listByPage(pageNum,pageSize,keyword);
        return AjaxResult.success("操作成功!",pageResult);
    }



}
